# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union
from fastapi import Query
from pydantic import BaseModel, Field


class DocsRecordSearchIn(BaseModel):
    """ 记录搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    user: Union[str, None] = Query(default=None, description="用户信息")
    is_free: Union[int, str, None] = Query(default=None, description="会员免费: [0=否, 1=是]")
    start_time: Union[int, str, None] = Query(default=None, description="开始时间")
    end_time: Union[int, str, None] = Query(default=None, description="结束时间")
    file_id: Union[int, None] = Query(default=0, ge=0, description="文件ID")
    filename: Union[str, None] = Query(default=None, description="文件名称")


class DocsRecordDeleteIn(BaseModel):
    """ 记录删除参数 """
    id: int = Field(..., ge=1, description="ID")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1
            }
        }


"""--------------- Separator ---------------"""


class DocsRecordListVo(BaseModel):
    id: int = Field(description="ID")
    file_id: int = Field(description="文件ID")
    code: str = Field(description="记录编号")
    scene: str = Field(description="来源场景")
    filename: str = Field(description="来源文件")
    question: str = Field(description="提问问题")
    answer: str = Field(description="答复内容")
    use_points: int = Field(description="消耗积分")
    use_tokens: int = Field(description="消耗Tokens")
    is_clear: int = Field(description="是否清除: [0=否, 1=是]")
    ip: str = Field(description="来源IP")
    task_time: str = Field(description="执行耗时")
    create_time: str = Field(description="记录时间")
    quotes: list = Field(description="引用内容")
    usages: list = Field(description="消耗情况")
    user: dict = Field(description="用户信息")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "file_id": 1,
                "code": "298ead761187f16952cf777f13272c77",
                "scene": "dialogue",
                "filename": "通知.pdf",
                "question": "这份文件印发于哪一年？",
                "answer": "这份文件印发于2020年。",
                "use_points": 2,
                "use_tokens": 289,
                "is_clear": 0,
                "ip": "127.0.0.1",
                "task_time": "2.88",
                "create_time": "2025-05-08 11:28:53",
                "quotes": [],
                "usages": [
                    {
                        "module": "AI 对话",
                        "name": "chat",
                        "use_points": 2,
                        "total_tokens": 289,
                        "prompt_tokens": 196,
                        "completion_tokens": 93
                    }
                ],
                "user": {
                    "sn": "52778960",
                    "nickname": "TW",
                    "mobile": "13800138000",
                    "avatar": "https://xx.com/avatar.png"
                }
            }
        }
